package br.com.automed.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="CM_CONSULTA")
@NamedQueries({
		@NamedQuery(name="Consulta.buscaConsulta", query="select o from Consulta o where o.dataConsulta = :param1 and o.medico = :param2"),
		@NamedQuery(name="Consulta.buscaConsultaPorArea", query="select o from Consulta o where o.medico.areaMedica = :param order by o.dataConsulta asc"),
		@NamedQuery(name="Consulta.buscaConsultaPorMedico", query="select o from Consulta o where o.medico.idUsuario = :param and o.flagAtendido = 'N' order by o.dataConsulta asc")
})
public class Consulta {
	
	public static final String NAMED_QUERY_BUSCA_CONSULTA = "Consulta.buscaConsulta";
	public static final String NAMED_QUERY_BUSCA_CONSULTA_POR_MEDICO = "Consulta.buscaConsultaPorMedico";
	
	@Id
    @GeneratedValue(generator = "system-uuid", strategy=GenerationType.AUTO)
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "ID_CONSULTA")
	private String idConsulta;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DT_CONSULTA")
	private Date dataConsulta;

	@Column(name = "FLAG_ATENDIDO")
	private String flagAtendido;
	
	@ManyToOne
	@JoinColumn(name="FK_PACIENTE", referencedColumnName="ID_PACIENTE")
	private Paciente paciente;
	
	@ManyToOne
	@JoinColumn(name="FK_TIPO_CONSULTA", referencedColumnName="ID_TIPO_CONSULTA")
	private TipoConsulta tipoConsulta;
	
	@ManyToOne
	@JoinColumn(name="FK_MEDICO", referencedColumnName="ID_MEDICO")
	private Medico medico;

	@ManyToOne
	@JoinColumn(name="FK_CONVENIO", referencedColumnName="ID_CONVENIO")
	private Convenio convenio;
	
	public String getIdConsulta() {
		return idConsulta;
	}
	public void setIdConsulta(String idConsulta) {
		this.idConsulta = idConsulta;
	}
	public Date getDataConsulta() {
		return dataConsulta;
	}
	public void setDataConsulta(Date dataConsulta) {
		this.dataConsulta = dataConsulta;
	}
	public String getFlagAtendido() {
		return flagAtendido;
	}
	public void setFlagAtendido(String flagAtendido) {
		this.flagAtendido = flagAtendido;
	}
	public Paciente getPaciente() {
		return paciente;
	}
	public void setPaciente(Paciente paciente) {
		this.paciente = paciente;
	}
	public TipoConsulta getTipoConsulta() {
		return tipoConsulta;
	}
	public void setTipoConsulta(TipoConsulta tipoConsulta) {
		this.tipoConsulta = tipoConsulta;
	}
	public Medico getMedico() {
		return medico;
	}
	public void setMedico(Medico medico) {
		this.medico = medico;
	}
	public Convenio getConvenio() {
		return convenio;
	}
	public void setConvenio(Convenio convenio) {
		this.convenio = convenio;
	}

}
